{extend name="../../admin/view/main"}
{block name='content'}
<form class="layui-form layui-card" action="{:request()->url()}" data-auto="true" method="post" autocomplete="off">
    <div class="layui-card-body padding-left-40">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>设备设置</legend>
        </fieldset>
        <div class="layui-form-item layui-row layui-col-space15">
            <div class="layui-col-xs6 block relative">
                <span class="color-green label-required-prev">设备柜点</span><span class="margin-left-5 color-desc">Device Type</span>
                <select class="layui-select" lay-search name="store_id">
                    <option selected value="">请选择 设备柜点</option>
                    {foreach $stores as $row}
                    {if isset($vo.store_id) AND $vo.store_id eq $row['id']}
                    <option selected value="{$row['id']}">{$row['name']}</option>
                    {else}
                    <option value="{$row['id']}">{$row['name']}</option>
                    {/if}
                    {/foreach}
                </select>
            </div>
            <label class="layui-col-xs6 block relative">
                <span class="color-green label-required-prev">设备编号</span><span class="margin-left-5 color-desc">Device Number</span>
                <input class="layui-input" name="device_no" required value="{$vo.device_no|default=''}" placeholder="请输入设备编号">
            </label>
        </div>

        <div class="layui-form-item layui-row layui-col-space15">
            <label class="layui-col-xs6 block relative">
                <span class="color-green label-required-prev">主板编号</span><span class="margin-left-5 color-desc">Board Number</span>
                <input class="layui-input" name="device_id" value="{$vo.device_id|default=''}" placeholder="请输入主板编号">
            </label>
            <label class="layui-col-xs6 block relative">
                <span class="color-green label-required-prev">箱格数量</span><span class="margin-left-5 color-desc">Box Count</span>
                <input class="layui-input" name="box_count" required value="{$vo.box_count|default=''}" placeholder="请输入设备箱格数量">
            </label>
        </div>

        <div class="layui-form-item layui-row layui-col-space15">
            <div class="layui-col-xs6 block relative">
                <span class="color-green label-required-prev">收费模式</span><span class="margin-left-5 color-desc">Fee Type</span>
                <select class="layui-select" lay-search lay-filter="fees" name="fee_id">
                    <option selected value="">请选择 收费模式</option>
                    {foreach $fees as $key=>$fee}
                    {if isset($vo.fee_id) AND $vo.fee_id eq $key}
                    <option selected data-fee_type="{$fee.fee_type}" value="{$key}">{$fee.title}</option>
                    {else}
                    <option data-fee_type="{$fee.fee_type}" value="{$key}">{$fee.title}</option>
                    {/if}
                    {/foreach}
                </select>
                <input type="hidden" id="fee_type" name="fee_type" value="{$vo.fee_type}">
            </div>

            <div class="layui-col-xs6 block relative">
                <span class="color-green label-required-prev">设备类型</span><span class="margin-left-5 color-desc">Device Type</span>
                <select class="layui-select" lay-search name="device_type">
                    <option selected value="">请选择 设备类型</option>
                    {foreach $device_types as $key=>$type}
                    {if isset($vo.device_type) AND $vo.device_type eq $key}
                    <option selected value="{$key}">{$type}</option>
                    {else}
                    <option value="{$key}">{$type}</option>
                    {/if}
                    {/foreach}
                </select>
            </div>
        </div>

        <div class="layui-form-item layui-row layui-col-space15">
            <label class="layui-col-xs6 block relative">
                <span class="color-green label-required-prev">联系人姓名</span><span class="margin-left-5 color-desc">Contact Name</span>
                <input class="layui-input" name="contacts" required value="{$vo.contacts|default=''}" placeholder="请输入联系人姓名">
            </label>
            <label class="layui-col-xs6 block relative">
                <span class="color-green label-required-prev">联系人电话</span><span class="margin-left-5 color-desc">Contact Number</span>
                <input class="layui-input" name="contact_number" lay-verify="required|phone|number" required value="{$vo.contact_number|default=''}" placeholder="请输入联系人电话">
            </label>
        </div>

        <div class="layui-form-item layui-row layui-col-space15">
            <label class="layui-col-xs4 block relative">
                <span class="color-green label-required-prev">设备状态</span><span class="margin-left-5 color-desc">Device Status</span><br>
                <div class="layui-input-inline">
                    {assign  name="status" value="$vo.status|default=1"}
                    <input type="radio" name="status" value="1" title="正常" {if $status==1}checked{/if}>
                    <input type="radio" name="status" value="0" title="停用" {if $status!=1}checked{/if}>
                </div>
            </label>
            <label class="layui-col-xs4 block relative">
                <span class="color-green label-required-prev">是否在用</span><span class="margin-left-5 color-desc">Device Used</span><br>
                <div class="layui-input-inline">
                    {assign  name="is_use" value="$vo.is_use|default=2"}
                    <input type="radio" name="is_use" value="1" title="是" {if $is_use==1}checked{/if}>
                    <input type="radio" name="is_use" value="2" title="否" {if $is_use==2}checked{/if}>
                </div>
            </label>
            <label class="layui-col-xs4 block relative">
                <span class="color-green label-required-prev">中途取物</span><span class="margin-left-5 color-desc">Pick up on the way</span><br>
                <div class="layui-input-inline">
                    {assign name="half_type" value="$vo.half_type|default=1"}
                    <input type="radio" name="half_type" value="1" title="允许" {if $half_type==1}checked{/if}>
                    <input type="radio" name="half_type" value="0" title="不允许" {if $half_type!=1}checked{/if}>
                </div>
            </label>

        </div>

        <div class="layui-form-item layui-row layui-col-space15">
            <label class="layui-col-xs6 block relative">
                <span class="color-green font-w7 label-required-prev">设备图片</span>
                <span class="color-desc margin-left-5">Conver Image</span>
                <label class="relative block label-required-null">
                    <input required name="image" value='{$vo.image|default=""}' placeholder="请上传设备图片&nbsp;&nbsp;&nbsp;&nbsp;" class="layui-input">
                    <a data-file data-type="png,jpg,gif" data-field="image" class="input-right-icon layui-icon layui-icon-upload"></a>
                    <script>$('[name="image"]').uploadOneImage()</script>
                </label>
            </label>
            <label class="layui-col-xs6 block relative">
                <span class="color-green">备注信息</span><span class="margin-left-5 color-desc">Start Hours</span>
                <textarea class="layui-textarea" name="remark" cols="3" placeholder="请输入备注信息">{$vo.remark|default=''}</textarea>
            </label>
        </div>
    </div>
    <div class="hr-line-dashed"></div>
    {notempty name='vo.id'}<input type='hidden' value='{$vo.id}' name='id'>{/notempty}

    <div class="layui-form-item text-center" style="padding-bottom: 20px;">
        {if $title!="查看设备"}
        <button class="layui-btn" lay-submit lay-filter="submit">保存数据</button>
        <button class="layui-btn layui-btn-danger" type='button' data-confirm="确定要取消编辑吗？" data-history-back>取消编辑</button>
        {/if}
    </div>

</div>

</form>
{/block}

{block name='script'}
<script src="/static/plugs/city-picker/city-picker.data.js"></script>
<script>
    (function () {
        var title = "{$title}";
        if(title=='查看设备'){
            $("input,select").attr("readOnly", true);
        }

        layui.form.on('select(fees)',function (data){
            let fee_type = data.elem[data.elem.selectedIndex].dataset.fee_type
            if(fee_type!=undefined){
                $("#fee_type").val(fee_type);
            }
        });

        layui.form.on('radio', function(data){
            $(this).val(data.value);
        });

        layui.form.render();

        window.form.on('radio', radios);

        function radios(data) {
            key = $(this).attr('name');
            $("input[name="+key+"]").val(data.value);
        }

    })();
</script>
{/block}